﻿Imports System.Data.SqlClient
Imports System.Text
Imports System.Security.Cryptography
Imports System.IO
Public Class DataProvider

    Public Function GiaiMa(ByVal base64 As String) As Byte()
        If base64 Is Nothing Then Throw New ArgumentNullException("base64")
        Return Convert.FromBase64String(base64)
    End Function

    Public Function ConnectionData() As SqlConnection

        Dim reader As StreamReader = New StreamReader("config.txt")

        Dim strSrName As String = reader.ReadLine()
        Dim strDbName As String = reader.ReadLine()
        reader.Close()

        strSrName = System.Text.Encoding.UTF8.GetString(GiaiMa(strSrName))
        strDbName = System.Text.Encoding.UTF8.GetString(GiaiMa(strDbName))

        Dim connectionString As String = "Data Source=" + strSrName + ";Initial Catalog=" + strDbName + ";Integrated Security=True"

        Dim cn As New SqlConnection(connectionString)
        cn.Open()
        Return cn
    End Function
    Public Function ConnectionDataDefault() As SqlConnection
        Dim connectionString As String = "Data Source=.;Integrated Security=True"
        Dim cn As New SqlConnection(connectionString)
        cn.Open()
        Return cn
    End Function
    Public Function GetTable(ByVal str As String) As DataTable
        Dim cnn As New SqlConnection
        Dim dataProvider As New DataProvider
        Dim da As SqlDataAdapter
        cnn = dataProvider.ConnectionDataDefault()
        da = New SqlDataAdapter(str, cnn)
        Dim data As New DataTable
        Try
            da.Fill(data)
        Catch ex As Exception

        End Try
        Return data
    End Function
End Class
